package org.xlp.auto.create;

import org.xlp.auto.create.exception.AutoCreatorDataLoseException;
import org.xlp.utils.XLPStringUtil;

/**
 * Description: 实体java文件自动创建类
 * <br/>date: 2023/11/30 11:05
 *
 * @version 1.0
 * @author: xlp
 */
public class EntityAutoCreator extends AbstractAutoCreator{
    public EntityAutoCreator() {
        setSubPackageName(Constants.ENTITY_SUB_PACKAGE_NAME);
    }

    /**
     * 构造函数
     * @param entityName
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public EntityAutoCreator(String entityName) {
        setEntityName(entityName);
        setSubPackageName(Constants.ENTITY_SUB_PACKAGE_NAME + "." + getEntityName().toLowerCase());
    }

    /**
     * 构造函数
     *
     * @param abstractAutoCreator
     * @throws NullPointerException 假如参数为null，则抛出该异常
     */
    public EntityAutoCreator(AbstractAutoCreator abstractAutoCreator) {
        super(abstractAutoCreator);
        setSubPackageName(Constants.ENTITY_SUB_PACKAGE_NAME + "." + getEntityName().toLowerCase());
    }

    /**
     * Java文件导入包内容
     *
     * @return
     */
    @Override
    protected String makeImportContent() {
        // 导入包
        return "import org.xlp.javabean.annotation.Bean;\n" +
               "import org.xlp.db.tableoption.annotation.XLPEntity;\n";
    }

    /**
     * java文件注解类容
     *
     * @return
     */
    @Override
    protected String makeAnnotationContent() {
        return "@Bean\n" +
               "@XLPEntity(tableName = \"表名称\", descriptor = \"描述\")\n";
    }

    /**
     * 获取java文件名称
     *
     * @return
     * @throws AutoCreatorDataLoseException 假如获取失败，则抛出该异常
     */
    @Override
    protected String getFileName() throws AutoCreatorDataLoseException {
        if (XLPStringUtil.isEmpty(getEntityName())){
            throw new AutoCreatorDataLoseException("实体名称未设置。");
        }
        return getEntityName() + Constants.JAVA_FILE_SUFFIX;
    }
}
